package com.titanium.exer1;

/**
 * @program: JavaSenior
 * @description:
 *
 * 练习： 创建2个分线程
 *  其中一个线程变量100以内的偶素
 *  另一个线程 变量100以内的奇数
 *
 *
 * @author: renfei.huang
 * @create: 2021-09-28 20:56
 */
public class ThreadDemo {

    public static void main(String[] args) {


        //方式一  普通创建
//        MyThread1 myThread1 = new MyThread1();
//        MyThread2 myThread2 = new MyThread2();
//        myThread1.start();
//        myThread2.start();


        //方式二 创建Thread匿名子类的方式
        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 100 ; i++) {
                    if(i % 2 == 0){
                        System.out.println("MyThread1:"+Thread.currentThread().getName()+":" + i);
                    }
                }
            }
        }.start();


        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 100 ; i++) {
                    if(i % 2 != 0){
                        System.out.println("MyThread2:"+Thread.currentThread().getName()+":" + i);
                    }
                }
            }
        }.start();




    }

}

class MyThread1 extends  Thread{
    @Override
    public void run() {
        for (int i = 0; i < 100 ; i++) {
            if(i % 2 == 0){
                System.out.println("MyThread1:"+Thread.currentThread().getName()+":" + i);
            }
        }
    }
}
class MyThread2 extends  Thread{
    @Override
    public void run() {
        for (int i = 0; i < 100 ; i++) {
            if(i % 2 != 0){
                System.out.println("MyThread2:"+Thread.currentThread().getName()+":" + i);
            }
        }
    }
}
